package com.learn.datasource;

import org.apache.flink.api.java.io.TextInputFormat;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.FileProcessingMode;

/**
 * @create: 2023-04-17 23:18
 * @author: Mr.Du
 * --------------
 * @notes: 流的方式读取文件
 **/
public class StreamFromFile {
    public static void main(String[] args) throws Exception {
        Configuration configuration = new Configuration();
        configuration.setInteger("rest.port", 8181); //设置webui的端口
        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(configuration);

        String path = "./data/input/wordcount.txt";

        DataStreamSource<String> lines = env.readFile(new TextInputFormat(null), path,
                FileProcessingMode.PROCESS_CONTINUOUSLY, 2000);

        int parallelism = lines.getParallelism();
        System.out.println("readFile创建的DataStream的并行度为：" + parallelism);
        lines.print();
        env.execute();
    }
}
